<template>
    <div class="sell_stock">
      <van-nav-bar
        title="卖出股份"
        left-arrow
        @click-left="$router.back()"
        left-text="返回"
      />
      <com-sell-stock :myStockInfo="myStockInfo" @getSellParam="getSellParam"></com-sell-stock>
    </div>
</template>

<script>
  import comSellStock from '../../components/comSellStock';
  import {Toast} from 'vant';

  export default {
    name: 'sellStock',
    data(){
      return {
        myStockInfo: '',
      }
    },
    created() {
      const myStockInfo = this.$route.params.myStockInfo || localStorage.getItem('myStockInfo')
      // 若有myStockInfo, 则保存
      if (myStockInfo) {
        if (this.$route.params.myStockInfo) {
          localStorage.setItem('myStockInfo', myStockInfo)
        }
        this.myStockInfo = JSON.parse(localStorage.getItem('myStockInfo'))
      } else {
        this.$router.push('/groupStock')
        localStorage.removeItem('myStockInfo')
      }
    },
    methods: {
      getSellParam(data){
        this.$api.stock.reqSellStock(data).then(res =>{
          if(res.code===200){
            Toast(res.data)
            this.$router.push('/groupStock/stockMarket')
          }
        })
      }
    },
    components: {
      ComSellStock: comSellStock,
    },
  }
</script>

<style scoped>

</style>
